<template>
 <el-form :model="ruleForm2" :rules="rules2" ref="ruleForm2" label-position="left" label-width="100px" class="demo-ruleForm login-container">
    <h3 class="title"></h3>
    <el-form-item label="原密码" prop="password">
      <el-input type="password" v-model="ruleForm2.password" auto-complete="off" placeholder="原密码"></el-input>
    </el-form-item>
    <el-form-item label="新密码" prop="newPassword">
      <el-input type="password" v-model="ruleForm2.newPassword" auto-complete="off" placeholder="新密码"></el-input>
    </el-form-item>
	 <el-form-item label="确认新密码" prop="checkPassword">
      <el-input type="password" v-model="ruleForm2.checkPassword" auto-complete="off" placeholder="确认新密码"></el-input>
    </el-form-item>

    <el-form-item style="width:100%;">
      <el-button type="primary" style="width:100%;" @click.native.prevent="savePassword" :loading="logining">保存</el-button>
      <!--<el-button @click.native.prevent="handleReset2">重置</el-button>-->
    </el-form-item>
  </el-form>
</template>
<script>
import translatorApi from "../../api/TranslatorApi";
import Toast from "../../util/Toast";

export default {
  data() {
    return {
      logining: false,
      ruleForm2: {
        password: "",
        newPassword: "",
        checkPassword: ""
      },
      rules2: {
        password: [
          { required: true, message: "请输入原密码", trigger: "blur" }
          //{ validator: validaePass }
        ],
        newPassword: [
          { required: true, message: "请输入新密码", trigger: "blur" }
          //{ validator: validaePass2 }
        ],
        checkPassword: [
          { required: true, message: "请再确认新密码", trigger: "blur" }
          //{ validator: validaePass2 }
        ]
      }
    };
  },
  methods: {

    savePassword(ev) {
      var _this = this;

      //验证密码
      if (_this.ruleForm2.newPassword != _this.ruleForm2.checkPassword) {
        Toast.show("两次密码不一致，请重新输入");
       /* _this.$message({
          message: "两次密码不一致，请重新输入",
          type: "error"
        });*/
        _this.logining = false;
      } else {
        translatorApi.requestModifyPassword(
          _this.ruleForm2.password,
          _this.ruleForm2.newPassword,
          function callback(response) {
            _this.logining = false;
            //if (response.isSuccess()) {
              //self.$router.replace("/");
            //} 
            Toast.show(response.message);
          }
        );
      }
    }
  }
};
</script>

<style scoped>
</style>